<template>
  <div class="page-wrapper">
    <header class="page-header">
      <div class="header-content">
        <img src="./logo.png" alt="农业电商系统logo" class="site-logo" aria-label="农业电商系统首页logo" role="img">
        <h1 class="site-title" id="main-title">农业电商系统</h1>
        <nav class="main-nav" aria-label="主菜单栏">
          <ul class="nav-links">
            <li><router-link to="/" class="nav-link" aria-label="前往首页">首页</router-link></li>
            <li><router-link to="/product" class="nav-link" aria-label="前往支付方式页面">支付方式</router-link></li>
           
            <li><router-link to="/user" class="nav-link" aria-label="前往个人中心页面">个人中心</router-link></li>
          
             <li><router-link to="/cart" class="nav-link" aria-label="前往更多农产品页面">更多农产品信息</router-link></li>
          </ul>
          <button class="nav-toggle" @click="toggleNav" aria-label="切换导航栏展开/收起状态">
            <span></span>
            <span></span>
            <span></span>
          </button>
        </nav>
      </div>
    </header>
    <main class="main-content-area">
      <aside class="sidebar" v-if="!isNavOpen &&!isMobile" aria-label="侧边栏，包含分类、搜索等功能">
        <!-- 侧边栏内容，如分类、搜索等 -->
      </aside>
      <section class="content-section" aria-label="主要内容区域">
        <router-view></router-view>
      </section>
    </main>
    <footer class="page-footer" aria-label="页面底部，包含版权等信息">
      <p class="footer-text">© 2024 农业电商系统. 版权所有.</p>
    </footer>
  </div>
</template>

<script setup>
import { ref, onMounted, onBeforeUnmount } from 'vue';

const isNavOpen = ref(false);
const isMobile = ref(window.innerWidth <= 768);
const isTablet = ref(window.innerWidth <= 1024 && window.innerWidth > 768);

const toggleNav = () => {
  isNavOpen.value =!isNavOpen.value;
  document.body.style.overflow = isNavOpen.value? 'hidden' : 'auto';
};

const handleResize = () => {
  isMobile.value = window.innerWidth <= 768;
  isTablet.value = window.innerWidth <= 1024 && window.innerWidth > 768;
  if (isMobile.value) {
    closeNavOnMobile();
  }
};

const closeNavOnMobile = () => {
  if (isNavOpen.value) {
    isNavOpen.value = false;
    document.body.style.overflow = 'auto';
  }
};

onMounted(() => {
  window.addEventListener('resize', handleResize);
});

onBeforeUnmount(() => {
  window.removeEventListener('resize', handleResize);
});
</script>

<style scoped>
/* 全局重置和通用样式（通常放在全局样式文件中） */
*,
::before,
::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: Arial, sans-serif;
  line-height: 1.6;
  background-color: #f4f4f4;
  color: #333;
  overflow-x: hidden;
}

/* 页面包装器 */
.page-wrapper {
  display: flex;
  flex-direction: Column;
  min-height: 100vh;
}

/* 页面头部 */
.page-header {
  background-color: #fff;
  padding: 15px 20px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  position: relative;
  z-index: 1000;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
}

.site-logo {
  height: 50px;
  width: auto;
  margin-right: 20px;
  transition: transform 0.3s ease-in-out;
}

.site-logo:hover {
  transform: scale(1.1);
}

.site-title {
  font-size: 2.5em;
  color: #3498db;
  margin: 0;
}

/* 主导航栏 */
.main-nav {
  display: flex;
  align-items: center;
  position: relative;
}

.nav-links {
  display: flex;
  list-style: none;
  padding: 0;
  margin: 0;
  gap: 20px;
  position: relative;
  z-index: 1;
}

.nav-link {
  text-decoration: nil;
  color: #555;
  font-size: 1em;
  padding: 10px 15px;
  border-radius: 4px;
  transition: background-color 0.3s, color 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  position: relative;
}

.nav-link:hover {
  background-color: #f0f0f0;
  color: #3498db;
}

.nav-link.router-link-active {
  background-color: #3498db;
  color: #fff;
}

/* 导航切换按钮 */
.nav-toggle {
  display: none;
  flex-direction: column;
  cursor: pointer;
  justify-content: center;
  width: 30px;
  height: 20px;
  background-color: transparent;
  border: nil;
  padding: 0;
}

.nav-toggle span {
  height: 4px;
  width: 100%;
  background-color: #333;
  border-radius: 2px;
  transition: all 0.3s ease-in-out;
  position: relative;
}

.nav-toggle span:not(:last-child) {
  margin-bottom: 4px;
}

.nav-toggle.active span:nth-child(1) {
  transform: translateY(10px) rotate(45deg);
}

.nav-toggle.active span:nth-child(2) {
  opacity: 0;
}

.nav-toggle.active span:nth-child(3) {
  transform: translateY(-10px) rotate(-45deg);
}

/* 导航栏下拉菜单样式 */
.main-nav-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background-color: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  min-width: 150px;
  z-index: 1001;
}

.main-nav-dropdown li {
  padding: 10px 15px;
  list-style: nil;
  cursor: pointer;
  transition: background-color 0.3s;
}

.main-nav-dropdown li:hover {
  background-color: #f0f0f0;
}

.nav-links li:hover >.main-nav-dropdown {
  display: block;
}

/* 响应式设计 */
@media (max-width: 768px) {
  /* 页面头部 */
 .page-header {
    padding: 10px 15px;
  }

 .site-logo {
    height: 40px;
    margin-right: 10px;
  }

 .site-title {
    font-size: 2em;
  }

  /* 主导航栏 */
 .main-nav {
    flex-direction: column;
    align-items: flex-start;
  }

 .nav-links {
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
  }

 .main-nav.is-nav-open.nav-links {
    max-height: 300px;
  }

 .nav-toggle {
    display: flex;
  }

  /* 侧边栏 */
 .sidebar {
    display: none;
  }

  /* 主内容区域 */
 .main-content-area {
    padding: 10px;
  }

 .content-section {
    padding: 10px;
  }
}

@media (max-width: 1024px) and (min-width: 769px) {
  /* 页面头部 */
 .page-header {
    padding: 12px 18px;
  }

 .site-logo {
    height: 45px;
    margin-right: 15px;
  }

 .site-title {
    font-size: 2.2em;
  }

  /* 主导航栏 */
 .main-nav {
    gap: 15px;
  }

 .nav-links {
    gap: 15px;
  }

  /* 侧边栏 */
 .sidebar {
    width: 200px;
    padding: 15px;
  }

  /* 主内容区域 */
 .main-content-area {
    padding: 15px;
  }

 .content-section {
    padding: 15px;
  }
}

/* 页脚 */
.page-footer {
  background-color: 3498db;
  color: #fff;
  text-align: center;
  padding: 20px 0;
}

.footer-text {
  margin: 0;
}
</style>